package com.labrecruit.system.controller;

import com.labrecruit.system.core.AjaxResult;
import com.labrecruit.system.core.controller.BaseController;
import com.labrecruit.system.domain.StuApply;
import com.labrecruit.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户Controller层
 */
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
    @Autowired
    private IUserService userService;

    /**
     * 添加报名信息
     */
    @PostMapping("/adduser")
    public AjaxResult addUser(@Validated @RequestBody StuApply apply) {
        if(userService.checkUser(apply) == -2) {
            return error("你已经报名过啦，请不要重复报名");
        }
        if(userService.checkUser(apply) == -1){
            return error("未查询到你的信息，请退出或转人工审核");
        }
        if(userService.checkUser(apply) == 0) {
            return error("你的姓名或学号填写有误，请重新填写！");
        }
        return toAjax(userService.insertUser(apply));
    }

    /**
     * 添加待审核信息
     */
    @PostMapping("/addwait")
    public AjaxResult addWait(@Validated @RequestBody StuApply apply) {
        return toAjax(userService.insertWait(apply));
    }

}
